﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Utility;
using DAL;
using dotnetCHARTING;

public partial class Report_QuarterDepartmentCompleteRate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Chart1.Title = "部门年计划完成率分析";
        this.Chart1.XAxis.Label.Text = "";
        this.Chart1.YAxis.Label.Text = "完成率";
        this.Chart1.TempDirectory = "../Temp";
        this.Chart1.ShadingEffect = true;
        this.Chart1.SeriesCollection.Add(toChart());
        this.Chart1.Use3D = true;
        this.Chart1.Debug = false;
        this.Chart1.Mentor = false; 
    }


    /// <summary>
    /// 定制查询数据 
    /// </summary>
    /// <returns>DataSet</returns>
    public DataSet get()
    {
        string _spName = "Report_QuarterReportCompleteRateToChart";
        SqlParameter[] parms = new SqlParameter[1];
        parms[0] = new SqlParameter("@QuarterDate", Utility.HttpHelp.getParamsInt("QuarterDate"));
        return SqlHelper.ExecuteDataset(SqlHelper.getConn(), CommandType.StoredProcedure, _spName, parms);
    }

    //处理数据提供给图表
    dotnetCHARTING.SeriesCollection toChart()
    {
        dotnetCHARTING.SeriesCollection SC = new dotnetCHARTING.SeriesCollection();
        DataSet ds = get();
        DataTable _tabel = ds.Tables[ds.Tables.Count - 1];
        dotnetCHARTING.Series Pre = new dotnetCHARTING.Series();
        dotnetCHARTING.Series The = new dotnetCHARTING.Series();
        Pre.Name = "上年";
        The.Name = "本年";
        for (int b = 0; b < _tabel.Rows.Count; b++)
        {
            dotnetCHARTING.Element e = new dotnetCHARTING.Element();
            e.Name = _tabel.Rows[b]["DepartmentParentName"].ToString();
            e.YValue = Convert.ToDouble(_tabel.Rows[b]["PreQuarterCompleteCount"].ToString());
            Pre.Elements.Add(e);

        }
        for (int b = 0; b < _tabel.Rows.Count; b++)
        {
            dotnetCHARTING.Element e = new dotnetCHARTING.Element();
            e.Name = _tabel.Rows[b]["DepartmentParentName"].ToString();
            e.YValue = Convert.ToDouble(_tabel.Rows[b]["TheQuarterCompleteCount"].ToString());
            The.Elements.Add(e);

        }
        SC.Add(Pre);
        SC.Add(The);
        SC[0].DefaultElement.Color = System.Drawing.Color.FromArgb(49, 255, 49);
        SC[1].DefaultElement.Color = System.Drawing.Color.FromArgb(255, 255, 0);
        return SC;
    }
}
